import store from "../index.js"
import {
  getFieldQuery,
  getFieldQuery2
} from "@/services/information";

export default {
  namespaced: true,
  state: {
    AllData: {},
    meData: {}
  },

  mutations: {
    setAllData(state, data) {
      state.AllData = data
    },
    setMeData(state, data) {
      state.meData = data

    }
  },
  actions: {
    getAllData(ctx) {
      getFieldQuery(store.state.site.companyId, store.state.site.employeeId).then(res => {
        ctx.commit("setAllData", res)

      });
    },
    getMeData(ctx, data) {
      let {
        type,
        id,
        field
      } = data
      getFieldQuery2(store.state.site.companyId, store.state.site.companyId, type, id).then(res => {
        if (field) {

          res.forEach(element => {
            element[field] = {
              [`${element.fieldCode}`]: ""
            }
          });
        }
        ctx.commit("setMeData", res)
      });
    }
  }
}